package com.fengke.csc.action.member;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.fengke.csc.action.BaseAction;
import com.fengke.service.MemberService;
import com.fengke.service.vo.MemberVO;
import com.fengke.util.Constants;
import com.fengke.util.LoggerFactory;

public class MemberAction extends BaseAction {
	private static final long serialVersionUID = 6373994392792605259L;
	private Logger logger = LoggerFactory.getLogger(MemberAction.class);
	private MemberService memberService;
	private List<MemberVO> memberVOList = new ArrayList<MemberVO>();
	private MemberVO memberVO = new MemberVO();
	
	public String memberManager() {
		logger.debug("memberManager");
		if(memberVO == null) {
			memberVO = new MemberVO();
		}
		if(getPageBean().getCurrentPage() == null || getPageBean().getCurrentPage() <= 0) {
			getPageBean().setCurrentPage(1);
		}
		
		getPageBean().setPageSize(Constants.PageSize.CSC_PAGE_SIZE);
		
		// 获取总量
		Integer memberVOListSize = null;
		try {
			memberVOListSize = memberService.researchMemberListSize(memberVO);
		} catch (Exception e) {
			logger.error("检索会员总量失败！memberVO=" + memberVO, e);
		}
		
		if(memberVOListSize != null && memberVOListSize > 0) {
			getPageBean().setResultItemCount(memberVOListSize);
			try {
				memberVOList = memberService.researchMemberList(memberVO, (getPageBean().getCurrentPage() - 1) * getPageBean().getPageSize(), getPageBean().getPageSize());
			} catch (Exception e) {
				logger.error("检索商品失败！productVO=" + memberVO, e);
			}
		} else {
			getPageBean().setResultItemCount(0);
		}
		return Constants.ActionReturnName.SUCCESS;
	}
	
	public String deleteMember() {
		logger.debug("deleteManager...");
		
		return Constants.ActionReturnName.SUCCESS;
	}
	
	public MemberService getMemberService() {
		return memberService;
	}
	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	public List<MemberVO> getMemberVOList() {
		return memberVOList;
	}

	public void setMemberVOList(List<MemberVO> memberVOList) {
		this.memberVOList = memberVOList;
	}

	public MemberVO getMemberVO() {
		return memberVO;
	}

	public void setMemberVO(MemberVO memberVO) {
		this.memberVO = memberVO;
	}
}
